$(function () {
// 下拉
    function renderOptions(articleType){
        var str = "";
        for (var i = 0; i < articleType.length; i++) {
            str += '<option  value="' + articleType[i].val + '">' + articleType[i].text + '</option>';
        }
        $('#article-type').append(str);
    }

    var articlepage = layer.load(0);
    $.restPost('/article/doSelect',{
        token: window.localStorage.getItem('token'),
        id:$.getUrlLocation()
    }).done(function (msg,data) {
        layer.close(articlepage);
        var E = window.wangEditor
        var editor2 = new E('#article-content')
        editor2.create()
        $.restPost('/article/doGetEnumType',{type:'article'}).done(function(msg,_data){
            renderOptions(_data.list);
            $('#article-type').val(data.type);
            $("#article-title").val(data.title);
            $("#article-content").val(data.content);
            $("#article-sort").val(data.sort);
            $("#btn-result").on("click",function () {
                var index = layer.load(0);
                $.restPost('/article/doUpdate',{
                    token:window.localStorage.getItem('token'),
                    id:$.getUrlLocation(),
                    title:$("#article-title").val(),
                    content:$("#article-content").val(),
                    type:$('#article-type').val(),
                    sort:$('#article-sort').val()
                }).done(function (msg, data) {
                    layer.close(index)
                    // $("#article-title").val("")
                    $.rootSuccessDialog(msg,2000)
                }).fail(function (msg) {
                    layer.close(index)
                    $.rootErrorDialog(msg,2000)
                })
            })
        });
    })


})